package xps.and.uudaijia.userclient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.ocpsoft.prettytime.PrettyTime;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.data.baen.YHJBean;

public class YHJAdapterDaijia extends AbstractRecyclerYHJAdapter<YHJBean.ReturnBodyBean> {
    YHJBean.ReturnBodyBean or;

    PrettyTime p = new PrettyTime(new Locale("ZH_CN"));


    public YHJAdapterDaijia(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.yhj_daijia_item, parent, false);
        v.setOnClickListener(this);
        return new ViewHolder(v);
    }

    @Override
    protected void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        ViewHolder myViewHolder = (ViewHolder) holder;
        or = getItem(position);
        myViewHolder.itemView.setTag(position);
        myViewHolder.tvStartPos.setText(or.getCouponMoney()+"元");
        myViewHolder.tvEndPos.setText(getStrTime(or.getValidStartTime()) + "至" + getStrTime(or.getValidEndTime()));
    }

    // 将时间戳转为字符串
    public static String getStrTime(String cc_time) {
        String re_StrTime = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long lcc_time = Long.valueOf(cc_time);
        re_StrTime = sdf.format(new Date(lcc_time * 1000L));
        return re_StrTime;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_start_pos)
        TextView tvStartPos;
        @BindView(R.id.tv_end_pos)
        TextView tvEndPos;
        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }

}
